class Solution:
    def numRollsToTarget(self, d: int, f: int, target: int) -> int:
        MOD = 10**9 + 7
        t = max(target, f)
        dp = [[0 for _ in range(t + 1)] for _ in range(d + 1)]
        for i in range(1, f + 1):
            dp[1][i] = 1
        for i in range(2, d + 1):
            for j in range(1, target + 1):
                for k in range(1, f + 1):
                    rem = j - k
                    if rem <= 0:
                        continue
                    dp[i][j] = (dp[i][j] + dp[i - 1][rem]) % MOD

        return dp[d][target]
